<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //属性
      console.log(Math.E); //e
      console.log(Math.PI); //PI

      //方法
      console.log("最小值", Math.min(12, 2, 3, 4));
      console.log("最大值", Math.max(12, 2, 3, 4));

      console.log("四舍五入", Math.round(12.134));
      console.log("四舍五入", (12.134324).toFixed(2));
      //.toFixed(n) 四舍五入可以保留n位小数，但结果为字符型数据
      console.log("四舍五入", parseFloat((12.134324).toFixed(2)));
      //用parseFloat将字符型数字转换为浮点型

      console.log("向上取整", Math.ceil(12.134)); //13
      console.log("向上取整", Math.ceil(-12.134)); //-12
      console.log("向下取整", Math.floor(12.134)); //12
      console.log("向下取整", Math.floor(-12.134)); //-13

      console.log("随机函数", Math.random()); //[0-1）
      console.log("随机函数", Math.random(2)); //random中的参数为随机种子
      //需求：输出[30-88]之间的随机数
      console.log(
        "输出[30-88]之间的随机数",
        Math.ceil(Math.random() * 58 + 30)
      );

      console.log("2的3次方为", Math.pow(2, 3));

      console.log("9的平方根为", Math.sqrt(9));

      console.log("30°的正弦为", Math.round(Math.sin(Math.PI / 6) * 10) / 10);
      //在JS运算中必须将角度转换为弧度再运算
      console.log(
        "35°的余弦为",
        parseFloat(Math.cos((35 * Math.PI) / 180).toFixed(1))
      );
    </script>
  </body>
</html>
